#include <iostream>

using namespace std;
class Solution 
{
public:
	int Sum(int n)
	{
		int sum = 0;
		while (n)
		{
			int t = n % 10;
			sum += t * t;
			n /= 10;
		}
		return sum;
	}
    bool isHappy(int n) 
	{
		int slow = n, fast = Sum(n);
		while (slow != fast)
		{
			slow = Sum(slow);
			fast = Sum(Sum(fast));
		}
		return slow == 1;
    }
};

int main()
{
	int n = 19;
	Solution xz;
	int bo = xz.isHappy(n);
	if (bo)
	{
		cout << "true" << endl;
	}
	else
		cout << "fales" << endl;

	return 0;
}
